<?php

	include ("../includes/connect_db.php");
	include("../includes/core.php");

	// print_r($_POST);
	extract($_POST, EXTR_SKIP);

	$result = array();
	switch ($act) {
		case "datang_dari":
			$sql = "SELECT DISTINCT datang_dari FROM front_office WHERE datang_dari LIKE '%".$key."%' AND datang_dari IS NOT NULL";
			$query = mysql_query($sql);
			while ($baris = mysql_fetch_array($query)) {
				$data["source"] = $baris["datang_dari"];
				array_push($result, $data);
			}
			break;
		case "pergi_ke":
			$sql = "SELECT DISTINCT pergi_ke FROM front_office WHERE pergi_ke LIKE '%".$key."%' AND pergi_ke IS NOT NULL";
			$query = mysql_query($sql);
			while ($baris = mysql_fetch_array($query)) {
				$data["source"] = $baris["pergi_ke"];
				array_push($result, $data);
			}
			break;
		case "tipe_kunjungan":
			$sql = "SELECT DISTINCT tipe_kunjungan FROM front_office WHERE tipe_kunjungan LIKE '%".$key."%' AND tipe_kunjungan IS NOT NULL";
			$query = mysql_query($sql);
			while ($baris = mysql_fetch_array($query)) {
				$data["source"] = $baris["tipe_kunjungan"];
				array_push($result, $data);
			}
			break;
	}
	echo json_encode($result);
?>